package com.wzdigit.wms.raw.controller.trsn.report;

import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.client.Pager;
import com.wzdigit.wms.basic.client.PagerInfo;
import com.wzdigit.wms.raw.client.request.trsn.report.asntrsn.AsnTrsnRequest;
import com.wzdigit.wms.raw.client.response.asn.report.ortherasn.OrtherAsnEnums;
import com.wzdigit.wms.raw.client.response.trsn.report.asntrsn.AsnTrsnResponse;
import com.wzdigit.wms.raw.constant.RawWareConstant;
import com.wzdigit.wms.raw.service.trsn.report.AsnTrsnService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 入库凭证报表
 * Created by zyf on 2021/6/11 10:55
 */
@RestController
@Api(tags = "入库凭证报表")
@RequestMapping(value = RawWareConstant.API_VERSION)
public class AsnTrsnController {
    private final String REQUEST_MODEL = "/AsnTrsn";

    @Autowired
    private AsnTrsnService asnTrsnService;

    @ApiOperation(value = "获取入库凭证报表（分页）", notes = "获取入库凭证报表（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/SearchAsnTrsn", method = RequestMethod.GET)
    public PagerInfo<List<AsnTrsnResponse>> searchAsnTrsnReport(
            AsnTrsnRequest search, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        try {
            return asnTrsnService.searchAsnTrsnReport(search,pager);
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "导出入库凭证报表", notes = "导出入库凭证报表")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/ExportAsnTrsn", method = RequestMethod.GET)
    public void exportAsnTrsnReport(
            AsnTrsnRequest search,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            asnTrsnService.exportAsnTrsnReport(search,servletRequest,servletResponse);
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    @ApiOperation(value = "单据类型下拉框", notes = "单据类型下拉框")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/getEnums", method = RequestMethod.GET)
    public List<OrtherAsnEnums> getEnums(
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            return asnTrsnService.getOrtherAsnEnumsList();
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

}
